import time

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import abstract_event_listener as EC
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver import Keys
from selenium import webdriver

driver=webdriver.Firefox()
driver.maximize_window()
driver.get('https://tieba.baidu.com/')
time.sleep(20)

#点击注册
driver.find_element(By.XPATH,'//*[@id="com_userbar"]/ul/li[5]/div/a').click()
time.sleep(4)
#切换窗口
driver.switch_to.window(driver.window_handles[-1])
time.sleep(8)
#点击登录
driver.find_element(By.ID,'login_btn').click()
time.sleep(10)
#点击用户名登录
driver.find_element(By.XPATH,'//*[@id="TANGRAM__PSP_31__footerULoginBtn"]').click()
#强制等待
time.sleep(8)
#输入框输入账号
driver.find_element(By.ID,'TANGRAM__PSP_31__userName').send_keys('13381144084')
#输入框输入密码
driver.find_element(By.ID,'TANGRAM__PSP_31__password').send_keys('grq200566++')
#点击登录按钮(包含高级定位)
# driver.find_element(By.XPATH,'//input[start-with(@id,"TANGRAM__")]')
# time.sleep(5)
driver.find_element(By.XPATH,'//*[@id="TANGRAM__PSP_31__submit"]').click()
time.sleep(25)
#点击搜索框
# driver.find_element(By.XPATH,'//input[contains(@class,"search_inp_border ")]')
# time.sleep(3)
a=driver.find_element(By.NAME,'kw1')
a.send_keys('小米')
time.sleep(3)
# #键盘清除按钮
# a.send_keys(Keys.CLEAR)
# time.sleep(3)
# a.send_keys('小米a')
# #键盘删除按钮
# a.send_keys(Keys.DELETE)
# time.sleep(3)
# # #键盘添加按钮
# # a.send_keys(Keys.ADD)
# # #键盘全选
# # a.send_keys(Keys.ALT)
# #键盘回车按钮
a.send_keys(Keys.ENTER)
time.sleep(3)
a.send_keys(Keys.ALT)
#点击小米
driver.find_element(By.XPATH,'//*[@id="head"]/div/div[2]/div/div[2]/ul/li[1]/div/div/div[1]/em').click()
#隐式等待
driver.implicitly_wait(15)
# #点击关注按钮
driver.find_element(By.CSS_SELECTOR,'#j_head_focus_btn').click()
time.sleep(5)
#显示等待
# ab=WebDriverWait(driver,40,0.5).until(EC,driver.execute_async_script(By.CSS_SELECTOR,'#j_head_focus_btn'))
# ab.click()
# time.sleep(5)